package com.xiaofan.controller;

import com.xiaofan.bean.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 晓帆
 * @version 1.0
 **/
@RestController
public class UserController {
    @RequestMapping("user")
    public String getUser(@Validated User user, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            FieldError fieldError = bindingResult.getFieldError();
            String defaultMessage = fieldError.getDefaultMessage();
            String field = fieldError.getField();
            System.out.println(field);
            System.out.println(field+defaultMessage);
            return "false";
        }
        return "ok";
    }
}
